package com.sinosoft.hydra.um.domain.model;

import cn.com.sinux.spring.utils.BeanUtils;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/6/20.
 */
public class DirectoryType implements Serializable {

    private String dirGroup;
    private String dirGroupValue;
    private boolean single;
    private boolean display;

    public boolean isDisplay() {
        return display;
    }

    private List<DirectoryType> directoryTypes = new ArrayList<DirectoryType>();

    public boolean isSingle() {
        return single;
    }

    public void setSingle(boolean single) {
        this.single = single;
    }

    public void setDisplay(boolean display) {
        this.display = display;
    }

    public List<DirectoryType> getDirectoryTypes() {
        return directoryTypes;
    }

    private static DirectoryType factory;

    public static DirectoryType createFactory(List<DirectoryType> directoryTypes) {
        if (factory == null) {
            factory = new DirectoryType();
            factory.getDirectoryTypes().addAll(directoryTypes);
        }
        return factory;
    }

    public static void destroy() {
        factory = null;
    }

    public String name() {
        return dirGroup;
    }

    public static List<DirectoryType> values() {
        return factory.getDirectoryTypes();
    }

    public static DirectoryType valueOf(String dirGroup) {
        if(StringUtils.isNotBlank(dirGroup)){
            for (DirectoryType directoryType : factory.getDirectoryTypes()) {
                if (dirGroup.equals(directoryType.getDirGroup())) {
                    DirectoryType dd = new DirectoryType();
                    BeanUtils.copyProperties(directoryType, dd);
                    return dd;
                }
            }
        }
        return null;
    }

    public String getDirGroup() {
        return dirGroup;
    }

    public void setDirGroup(String dirGroup) {
        this.dirGroup = dirGroup;
    }

    public String getDirGroupValue() {
        return dirGroupValue;
    }

    public void setDirGroupValue(String dirGroupValue) {
        this.dirGroupValue = dirGroupValue;
    }
}
